import Block from "./features/Block";
import GridSystem from "./GridSystem";
// 元素分组
class Group {

    blocks: Block[]
    constructor() {
        this.blocks = []
        GridSystem.addGroup(this);
    }

    /**
     * 元素添加到组
     * @param block 
     * @returns true表示添加成功
     */
    add(block: Block):boolean {
        if(this.blocks.find(item=> item === block)) return false;
        this.blocks.push(block);
        return true;
    }

    remove(block: Block) {
        for (let index = 0; index < this.blocks.length; index++) {
            const t_block = this.blocks[index];
            if (t_block === block) {
                this.blocks.splice(index, 1)
            }
        }
    }

    clear() {
        this.blocks = []
    }
    
}

export default Group;